package cc.wanforme.chipmunity.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author wanne
 * 2019年11月16日
 * 
 */
@Configuration
public class RedisConfig {
	// 一个Spring默认的，一个自定义的
	
	// 非默认 redis 的配置
	@Value("spring.logRedis.Log.database")
	private String database;
	@Value("spring.logRedis.Log.host")
	private String host;
	@Value("spring.logRedis.Log.port")
	private int port;
	@Value("spring.logRedis.Log.password")
	private String password;
	@Value("spring.logRedis.Log.expire")
	private int expire;
	
	
	// 默认的
	@Bean(name = "defaultRedis")
	@Primary
	public StringRedisTemplate template(RedisConnectionFactory connectionFactory) {
		return new StringRedisTemplate(connectionFactory);
	}
	
//	由于有 spring内置默认的，所以要么写两个 RedisConnectionFactory，设置一个默认的；要么直接就不显示写出来
//	@Primary
//    @Bean
//    public RedisConnectionFactory cacheRedisConnectionFactory() {
//        return createJedisConnectionFactory(dbIndex, host, port, password, timeout);
//    }
//	
	
	// 自定义的
	@Bean(name = "logRedis")
	public RedisTemplate<String, String> logTemplate(){
//		Gere config = new JedisPoolConfig();
//		GenericObjectPoolConfig config = new G
		JedisPool jedisPool = new JedisPool(config, host, port, expire, password, database, false);
		
	}
	
}
